import axios from 'axios';

const request = axios.create({
  baseURL: 'http://127.0.0.1:3030/',
  timeout: 20 * 1000,
  withCredentials: true
})

request.interceptors.request.use(
  (config) => {
    config.params = { ...config.params, timestamp: Date.now() };
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

request.interceptors.response.use(
  response => {
    // console.log('响应拦截器response', response);
    if (response.data.code === 503) {
      return Promise.reject(response.data.message);
    }
    return response.data;
  },
  error => {
    // if (error.response.data.message === '亲爱的,暂无版权') {
    //   return error.response.data
    // }
    return Promise.reject(error);
  }
);

export default request
